# 版本检查脚本
import importlib.metadata

# -- coding: utf-8 --
import sys
import io
from dotenv import load_dotenv

# 设置标准输出的编码为UTF-8
if sys.stdout.encoding != "UTF-8":
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")


def check_versions():
    """检查已安装的包版本"""
    packages = [
        "langchain",
        "langchain-core",
        "langchain-community",
        "langchain-openai",
    ]

    print("📦 已安装的包版本:")
    print("-" * 40)

    for package in packages:
        try:
            version = importlib.metadata.version(package)
            print(f"✅ {package}: {version}")
        except importlib.metadata.PackageNotFoundError:
            print(f"❌ {package}: 未安装")
        except Exception as e:
            print(f"⚠️  {package}: 检查失败 - {e}")


if __name__ == "__main__":
    check_versions()
